var models = require('../../db/models')
var server = require('../server')
var db = require('../../db/connect')
var encrypt = require('../../libs/encrypt')
var jsonres = require('../../libs/jsonres')
var querystring = require('querystring');

function timedGetText(cb){
const http = require("http")
const url = "http://dev.legendpoker.cn:8088/all?playerid=13882231811&platform=%E5%BE%B7%E6%89%91%E5%9C%88"
http.get(url,(res)=>{
    var html ="";
    res.on("data",(data)=>{
        html+=data
    })

    res.on("end",()=>{
        console.log(html)
        cb(html)
    })

}).on("error",(e)=>{
    console.log(`获取数据失败: ${e.message}`)
})}
server.get('/api/history',function(req,res) {
    var u = req.query.user
    var p = req.query.platform
    // 改为tasks
    //db.find('tasks',{platform: p, user: u, finished: true, },function(err,result) {
    timedGetText(function (html) {
        //content=JSON.parse(html.toString())
        //if (!!!err) {
        if (1==1){
             console.log(html)
            res.send(jsonres(200,'success',JSON.parse(html)))
        } else {
            res.send(jsonres(-1, '查询失败', err))
        }
    //})
})})
